package top.oneit.jdownload.test;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;

/**
 * @author lingkang
 */
public class MyParent extends MyStageCommon {
    public Button button;

    public MyParent() {
        setTitle("父窗口！");
        button = new Button("open子窗口A");
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if (getStage(MySonA.class) == null) {
                    new MySonA().show();// 显示子窗口
                } else {
                    getStage(MySonA.class).show();
                }
                // 调用子接口对象
                System.out.println(getStage(MySonA.class).button.getText());
            }
        });

        Button closeSon = new Button("关闭子窗口");
        closeSon.setLayoutY(40);
        closeSon.setOnAction(event -> {
            //if (getStage(MySonA.class) != null)
                getStage(MySonA.class).close();
        });

        AnchorPane anchorPane = new AnchorPane(button, closeSon);
        anchorPane.setPrefWidth(400);
        anchorPane.setPrefHeight(300);
        setScene(new Scene(anchorPane));
        show();
    }
}
